<div id="mySubView">

<h3>related links</h3>

<div id="floatingbar">
        <?php
            $this->widget('zii.widgets.jui.CJuiButton',
                    array(
                            'name'=>'button',
                            'caption'=>'new object link',
                            'value'=>'asd',
                            'onclick'=>'js:function(){
                                    $("#Objectlink_objectlink_id").val("");
                                    $("#sub_org_id").val("");
                                    $("#mySubViewForm").show();
                                    $("#myFilterSubViewForm").hide();
                                    $("#mySubViewFormFilters").hide();
                                    $("#rec_save_button").attr("value","Create");
                                }',
                            )
                    );
        ?>
</div>

<?php
$this->widget('zii.widgets.grid.CGridView', array(
	'dataProvider' => $dataprovider,
	'id'=>'objectlink_table',
        'selectionChanged'=>'updateEditForm',
	'columns' => array(
		array(
                    'value'=>'$data[\'objectlink_id\']',
                    'type'=>'raw',
                    'name'=>'objectlink_id',
                    'htmlOptions'=>array(
                            'style'=>'width:50px',
                    ),
                ),
                array(
                    'value'=>'$data[\'org_id\']',
                    'type'=>'raw',
                    'htmlOptions'=>array(
                            'style'=>'width:50px',
                            'class'=>'org_id',
                    ),
                    'name'=>'org_id',
                ),
                array(
                    'value'=>'$data[\'org\'][\'nachname\'] . ", " . $data[\'org\'][\'vorname\']',
                    'type'=>'raw',
                    'name'=>'Name',
                ),
                array(
                    'value'=>'Yii::app()->request->hostInfo.Yii::app()->createUrl("//objectlink/printQVObject", array("id" => $data[\'objectlink_id\'],"date" => date("Y-m-d")))',
                    'type'=>'raw',
                    'name'=>'ObjLink'
                ),                
                array(
                    'class'=>'CButtonColumn',
                    'template'=>'{delete}',
                    'deleteButtonUrl'=>'Yii::app()->createUrl("//objectlink/delete", array("id" => $data[\'objectlink_id\']))',                    
                ),
             ),
          ));

?>



    <div id="mySubViewForm">      
        
    <?php $this->renderPartial('//objectlink/_form', array('model'=>$submodel)); ?>

    </div>

    <div id="myFilterSubViewForm">

        <?php 
            $tmpcriteria=new CDbCriteria(
                    array(
                        'condition'=>'objectlink_id = 0',
            ));
                
            $tmpmodel = new CActiveDataProvider('ObjectQvfilters', array(
			'criteria'=>$tmpcriteria,
            ));
            
            $this->renderPartial('//objectqvfilters/subview', array('qvfmodel'=>$tmpmodel,'id'=>0)); ?>

    </div>

</div>

<script type="text/javascript">

$('#mySubViewForm').hide();
$('#myFilterSubViewForm').hide();

function updateEditForm(target_id){

    $('#Notification').jnotifyAddMessage({
	        text: 'Loading objectlink...',
	        permanent: false,
	        showIcon: true
    });

    var id =$.fn.yiiGridView.getSelection(target_id);

    $('#rec_save_button').attr('value', (id > 0 ? 'update' : 'create'));

    $.getJSON('<?php echo Yii::app()->createUrl("//objectlink/subviewload"); ?>'+'&id='+id,
			function(data) {
				$('#sub_org_id').val(data.nachname);
                                $('#Objectlink_org_id').val(data.org_id);
                                $('#Objectlink_objectlink_id').val(data.objectlink_id);
                                $('#Objectlink_object_id').val(data.object_id);
			});

    $.fn.yiiGridView.update('qvfilters-grid', {
        'type' :'POST',
        'url'  :'<?php echo Yii::app()->createUrl("//objectqvfilters/subview")?>'+'&id='+id
    });

    $("#ObjectQvfilters_objectlink_id").val($("#Objectlink_objectlink_id").val());
    $("#Qvfilters_filter").val("");
    $("#Qvfilters_fil_id").val(0);
    jQuery.ajax({"type":"POST","url":"<?php echo Yii::app()->createUrl('//qvmapping/loadValues') ?>","data":{"docName":"<?php echo strtoupper(Qvobjects::model()->findByPK(Objects::model()->findByPK($_GET['id'])->qvo_id)->qvo_docName); ?>","id":0},"success":function(html){jQuery("#qvv_values").html(html)}});
    $("#fil_save_button").attr("value","Create");
    
    $('#mySubViewForm').show();
    $('#myFilterSubViewForm').show();
    
   return false;
}

</script>